<%@ page language="java" import="java.util.*" contentType="text/html; charset=utf-8"%>
<%@page import="entity.*" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    <title>购物车</title>
	<link type="text/css" rel="stylesheet" href="css/style1.css" />
    <script language="javascript">
	    function delcfm() {
	        if (!confirm("确认要删除？")) {
	            window.event.returnValue = false;
	        }
	    }
   </script>
  </head>
  
  <body>
   	<h1>我的购物车</h1>
   	<a href="index.jsp">首页</a> >> <a href="index.jsp">商品列表</a>
   	<hr> 
   	<div id="shopping">
   		<form>		
			<table>
				<tr>
					<th>商品名称</th>
					<th>商品单价</th>
					<th>商品价格</th>
					<th>购买数量</th>
					<th>操作</th>
				</tr>
				<% 
				   //首先判断session中是否有购物车对象
				   	Cart cart = (Cart)request.getSession().getAttribute("cart");
				   	if(cart!=null){
				%>
				<!-- 循环的开始 -->
				    <% 
				        HashMap<Items,Integer> goods = cart.getGoods();//获得购物车中商品和数量
				        Set<Items> items = goods.keySet();//取得商品所有商品的集合
				        Iterator<Items> iterator = items.iterator();
				         
				        while(iterator.hasNext()){
				            Items i = iterator.next();
				    %> 
							<tr name="products" id="product_id_1">
								<td class="thumb"><img src="images/<%=i.getPicture()%>" /><a href=""><%=i.getName()%></a></td>
								<td class="number"><%=i.getPrice() %></td>
								<td class="price" id="price_id_1">
									<span><%=i.getPrice()*goods.get(i) %></span>
									<input type="hidden" value="" />
								</td>
								<td class="number"><%=goods.get(i)%></td> 
			                    <td class="delete">
								  <a href="servlet/CartServlet?action=delete&id=<%=i.getId()%>" onclick="delcfm();">删除</a>
								</td>
							</tr>
				    <% 
				         }
				    %>
				<!--循环的结束-->
			</table>
			<div class="total"><span id="total">总计：<%=cart.getTotalPrice() %>￥</span></div>
			  	<% 
			    	}
			 	%>
			<div class="button"><input type="submit" value="" /></div>
		</form>
	</div>
  </body>
</html>
